home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- # Access the environment variable by name
-
- $server_name = $ENV{'SERVER_NAME'};
-
- # Store the server port number
-
- $server_port = $ENV{'SERVER_PORT'};
-
- # Send the output mime type to the server to expect HTML output
-
- print "Content-type: text/html\n\n";
-
- # Print required HTML tags.
-
- print <<EOH;
- <HTML>
- <HEAD><TITLE>CGI Script How-To: Test Script</TITLE></HEAD>
- <BODY>
- EOH
-
- print "<H1>CGI Script How-to<BR>determine the server's name for self referencing URL's</H1>\n";
-
- if ($server_name)
- {
- # Define a self-referencing URL to the server's home page
-
- $url = "http://" . $server_name;
-
- # Check the port number.
-
- if ($server_port && $server_port != 80)
- {
- $url .= ":$server_port";
- }
-
- # Add the closing slash to terminate the URL
-
- $url .= "/";
-
- # Print the hyperlinked URL to the home page
-
- print "<H2>You can go to the home page of this server with the URL:\n";
- print qq!<A HREF="$url">$url</A></H2>\n!;
- }
- else
- {
- print "<H2>Server cannot be determined</H2>\n";
- }
-
- # Print closing HTML tags
-
- print "</BODY></HTML>\n";
-
- #
- # end of testserv.pl
- #
-